#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e6 + 5;
int arr[N];

int get(int x){
	int s=0;
	while(x) {
		s += x%10;
		x/=10;
	}
	return s;
}

void init() {
	memset(arr, -1, sizeof(arr));
	int pos = 1;
	int cnt = 0;
	while (pos <= 1e6) {
		arr[pos] = cnt;
		pos += get(pos);
		cnt++;
	}
}

void solve() {
	int n;
	cin >> n;
	cout << arr[n] << '\n';
	return ;
}

signed main() {
	int t;
	cin >> t;
	init();
	while (t--) {
		solve();
	}
	return 0;
}
